<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-pTask-add">
			<input name="lineId" type="hidden" id="line_id"/>
			<input name="byqId" type="hidden" id="byq_id"/>
			<input name="useId" type="hidden" id="use_id"/>
			<input name="auditorId" type="hidden" id="auditor_id"/>
			<div class="form-group">
				<label class="col-sm-3 control-label">任务名称：</label>
				<div class="col-sm-8">
					<input id="taskName" name="taskName" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group" hidden>
				<label class="col-sm-3 control-label">线路名称：</label>
				<div class="col-sm-8">
					<input id="line_name" name="lineName" class="form-control" type="text" onclick="chooseLine()">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">变压器：</label>
				<div class="col-sm-8">
					<input id="byq_name" name="byqName" class="form-control" type="text" onclick="chooseByq()">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">任务说明：</label>
				<div class="col-sm-8">
					<!--<input id="taskNote" name="taskNote" class="form-control" type="text">-->
					<textarea id="taskNote" name="taskNote" class="form-control" style="height: 100px;border: 1px solid #e5e6e7;">

					</textarea>
				</div>
			</div>
			<div class="form-group" hidden="true">
				<label class="col-sm-3 control-label">任务状态：</label>
				<div class="col-sm-8">
					<input id="taskStatus" name="taskStatus" class="form-control" type="text" value="新增" readonly>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">计划开始时间：</label>
				<div class="col-sm-8">
					<input id="pStartTime" name="pStartTime" class="form-control" type="date">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">计划结束时间：</label>
				<div class="col-sm-8">
					<input id="pEndTime" name="pEndTime" class="form-control" type="date">
				</div>
			</div>
			<div class="form-group" hidden="true">
				<label class="col-sm-3 control-label">实际开始时间：</label>
				<div class="col-sm-8">
					<input id="cStartTime" name="cStartTime" class="form-control" type="date">
				</div>
			</div>
			<div class="form-group" hidden="true">
				<label class="col-sm-3 control-label">实际结束时间：</label>
				<div class="col-sm-8">
					<input id="cEndTime" name="cEndTime" class="form-control" type="date">
				</div>
			</div>
			<div class="form-group" hidden="true">
				<label class="col-sm-3 control-label">任务分配时间：</label>
				<div class="col-sm-8">
					<input id="releaseTime" name="releaseTime" class="form-control" type="date">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">采集人：</label>
				<div class="col-sm-8">
					<input id="use_name" name="useName" class="form-control" type="text" onclick="chooseCollector(this)">
				</div>
			</div>
			<div class="form-group" hidden="true">
				<label class="col-sm-3 control-label">任务创建/分配人：</label>
				<div class="col-sm-8">
					<input id="createId" name="createId" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">审核人：</label>
				<div class="col-sm-8">
					<input id="auditor_name" name="auditorName" class="form-control" type="text" onclick="chooseCollector(this)">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "assets/pTask"
		$("#form-pTask-add").validate({
			rules:{
                taskName:{
					required:true,
				},
                lineName:{
                    required:true,
                },
                byqName:{
                    required:true,
                },
                taskNote:{
                    required:true,
                },
                pStartTime:{
                    required:true,
                },pEndTime:{
                    required:true,
                },
                useName:{
                    required:true,
                },
                auditorName:{
                    required:true,
                },
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-pTask-add').serialize());
	        }
	    }


        /**
		 *  线路名称选择
         */
        function chooseLine() {
            layer.open({
                type: 2,
                title: '上级线路选择',
                area: ['950px', '340px'],
                fixed: false, //不固定
                maxmin: true,
                content: ctx+"assets/iLine/chooseLine",
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function (index,layero) {
                    var body = layer.getChildFrame('body', index);//得到iframe页的body内容
                    $("#line_id").val(body.find('#line_id').val());
                    $("#line_name").val(body.find('#line_name').val());
                    layer.close(index);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }


        /**
         * 	选择变压器
         */
        function chooseByq(){
            //	打开方式一
            layer.open({
                type: 2,
                title: '变压器选择',
                area: ['950px', '340px'],
                fixed: false, //不固定
                maxmin: true,
                content: ctx+"assets/bByq/chooseByq",
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function (index,layero) {
                    var body = layer.getChildFrame('body', index);//得到iframe页的body内容
                    $("#byq_id").val(body.find('#byq_id').val());
                    $("#byq_name").val(body.find('#byq_name').val());
                    layer.close(index);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }


        /**
         * 	选择采集、审核人
         */
        function chooseCollector(e){

            var thisName = e.getAttribute("name");
            var attrName = "";
            if(thisName == "useName")
                attrName = "采集人";
            else
                attrName = "审核人";


            //	打开方式一
            layer.open({
                type: 2,
                title: attrName+'选择',
                area: ['530px', '370px'],
                fixed: false, //不固定
                maxmin: true,
                content: ctx+"assets/pTask/userAdd",
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function (index,layero) {
                    var body = layer.getChildFrame('body', index);//得到iframe页的body内容

                    // 获取所选的option长度
                    var optionLength = body.find("#right option").length;
                    if(optionLength>0){
                        var name = "";
                        var id = "";

                        for(var i=0 ; i<optionLength ; i++){
                            var userName = body.find("#right option")[i].text;	//	获取所选人员姓名
                            var userId = body.find("#right option")[i].value;	//	获取所选人员ID
                            if(i==optionLength-1){
                                name += userName;
                                id += userId;
                            }else{
                                name += userName+",";
                                id += userId+",";
                            }
                        }
                        //	采集人
                        if(thisName == "useName"){
                            $("#use_name").val(name);
                            $("#use_id").val(id);
                        }else{
                            //	审核人
                            $("#auditor_name").val(name);
                            $("#auditor_id").val(id);
                        }
                    }
                    layer.close(index);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }


	</script>
</body>
</html>
